// pages/account/student/student.js
let common = require('../../../utils/common.js')
Page({
  data: {
    loadHidden: true,
    hasMore: false,
    tipNone: true,
    students:[],
  },
  skip: 0,
  take: 10,
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      loadHidden: false
    });
    this.reqStudent();
  },
  reqStudent: function () {
    let that = this;
    common.asynPost(common.API.user.students, {
      skip: that.skip,
      take: that.take
    }, function (data) {
      that.setData({
        loadHidden: true
      });
      if (data['students'] && data['students'].length) {
        that.setData({
          students: data['students'],
          hasMore: true,
          tipNone: true,
        });
      } else {
        that.skip -= that.take;
        that.setData({
          hasMore: true,
          tipNone: false,
        });
      }
    }, function (err) {
      that.setData({
        loadHidden: true
      });
    });
  },
  onReachBottom: function () {
    var that = this;
    that.setData({
      tipNone: false,
      hasMore: false
    });
    that.skip += that.take;
    that.reqStudent();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  }
})